/**
 * @param {number[]} nums1
 * @param {number[]} nums2
 * @return {number[]}
 */
var nextGreaterElement = function(nums1, nums2) {
  let result = [];
  for(let i = 0; i < nums1.length; i++) {
    const index = nums2.indexOf(nums1[i]);
    if(index == nums2.length - 1) result.push(-1);
    for(let j = index + 1; j < nums2.length; j++) {
      if(nums2[j] > nums1[i]) {
        result.push(nums2[j]);
        break;
      }
      if(j == nums2.length - 1) {
        result.push(-1);
      }
    }
  }
  return result;
};
let nums1 = [4,1,2], nums2 = [1,3,4,2];
console.log(nextGreaterElement(nums1, nums2));
nums1 = [2,4], nums2 = [1,2,3,4];
console.log(nextGreaterElement(nums1, nums2));
